package com.cf.data.serve.environment;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cf.data.serve.entity.HjjcTj;
import com.cf.data.serve.entity.SbTjsb;
import com.cf.data.serve.entity.TjGzxh;
import com.cf.data.serve.entity.TjSjXx;
import com.cf.data.serve.service.*;
import com.cf.data.serve.utils.BeanUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@RequestMapping
@Slf4j
public class TjServer {
    @Autowired
    private HjjcTjService hjjcTjService;

    @Autowired
    private TjSjService tjSjService;

    @Autowired
    private TjGzxhService tjGzxhService;

    @Autowired
    private SbTjsbService sbTjsbService;

    //实时数据（发送间隔为 10 秒一次）
    @RequestMapping(value = "/sssj", method = RequestMethod.POST)
    public void sssj(String sn,String Height,String HeightPercent,String Range,String RangePercent,String Roration,String Weight,String WeightPercent,String Moment,String MomentPercent,String Angle,String AngleY,String Speed,String rate,String sensorWarn,String sensorAlarm,String SaftWeight,String latitude,String longitude,String time){
/*        System.out.println("-------------------------------------------------实时数据-------------------------------------------------");
        System.out.println("sn："+sn);
        System.out.println("Height："+Height);
        System.out.println("HeightPercent："+HeightPercent);
        System.out.println("Range："+Range);
        System.out.println("RangePercent："+RangePercent);
        System.out.println("Roration："+Roration);
        System.out.println("Weight："+Weight);
        System.out.println("WeightPercent："+WeightPercent);
        System.out.println("Moment："+Moment);
        System.out.println("MomentPercent："+MomentPercent);
        System.out.println("Angle："+Angle);
        System.out.println("AngleY："+AngleY);
        System.out.println("Speed："+Speed);
        System.out.println("rate："+rate);
        System.out.println("sensorWarn："+sensorWarn);
        System.out.println("sensorAlarm："+sensorAlarm);
        System.out.println("SaftWeight："+SaftWeight);
        System.out.println("latitude："+latitude);
        System.out.println("longitude："+longitude);
        System.out.println("time："+time);
        System.out.println("-------------------------------------------------结束-------------------------------------------------");*/
        HjjcTj hjjcTj = new HjjcTj();
        hjjcTj.setId(String.valueOf(System.currentTimeMillis()));
        hjjcTj.setState("0");
        hjjcTj.setAddTime(new Date());
        hjjcTj.setSn(sn);
        hjjcTj.setHeight(Height);
        hjjcTj.setHeightPercent(HeightPercent);
        hjjcTj.setRang(Range);
        hjjcTj.setRangePercent(RangePercent);
        hjjcTj.setRoration(Roration);
        hjjcTj.setWeight(Weight);
        hjjcTj.setWeightPercent(WeightPercent);
        hjjcTj.setMoment(Moment);
        hjjcTj.setMomentPercent(MomentPercent);
        hjjcTj.setAngle(Angle);
        hjjcTj.setAngleY(AngleY);
        hjjcTj.setSpeed(Speed);
        hjjcTj.setRate(rate);
        hjjcTj.setSensorWarn(sensorWarn);
        hjjcTj.setSensorAlarm(sensorAlarm);
        hjjcTj.setSaftWeight(SaftWeight);
        hjjcTj.setLatitude(latitude);
        hjjcTj.setLongitude(longitude);
        hjjcTj.setTime(time);
        hjjcTjService.save(hjjcTj);
        System.out.println("添加成功");
    }

    //参数数据（在设备重启或者设置后发送）
    @RequestMapping(value = "/cssj", method = RequestMethod.POST)
    public void cssj(String psn,String prate,String pmin_height_sensor_value,String pmax_height_sensor_value,String pstandard_length,String pmin_range,String pmin_range_sensor_value,String pmax_range,String pmax_range_sensor_value,String protation_leftlimit_sensor_value,String protation_rightlimit_sensor_value,String pmin_weight_sensor_value,String pmax_weight_sensor_value,String pfour_rate_max_weight,String pfour_rate_max_weight_range,String pfour_rate_max_range,String pfour_rate_max_range_weight,String ptwo_rate_max_weight,String ptwo_rate_max_weight_range,String ptwo_rate_max_range,String ptwo_rate_max_range_weight,String pheight_up_warn_advance,String pheight_up_alarm_advance,String pheight_down_warn_advance,String pheight_down_alarm_advance,String prange_in_warn_advance,String prange_in_alarm_advance,String prange_out_warn_advance,String prange_out_alarm_advance,String proration_right_warn_advance,String proration_right_alarm_advance,String proration_left_warn_advance,String proration_left_alarm_advance,String pspeed_exchange_weight,String pcutting_weight,String pspeed_exchange_torque,String pcutting_torque,String panti_collision_speedlimit,String panti_collision_cutlimit,String plocal_No,String pchannel_No,String pgroup_No,String plocation_type,String plocation_x,String plocation_y,String plifting_arm_length,String pbalance_arm_length,String ptower_body_height,String ptower_hat_height){
/*        System.out.println("-------------------------------------------------参数数据-------------------------------------------------");
        System.out.println("psn："+psn);
        System.out.println("prate："+prate);
        System.out.println("pmin_height_sensor_value："+pmin_height_sensor_value);
        System.out.println("pmax_height_sensor_value："+pmax_height_sensor_value);
        System.out.println("pstandard_length："+pstandard_length);
        System.out.println("pmin_range："+pmin_range);
        System.out.println("pmin_range_sensor_value："+pmin_range_sensor_value);
        System.out.println("pmax_range："+pmax_range);
        System.out.println("pmax_range_sensor_value："+pmax_range_sensor_value);
        System.out.println("protation_leftlimit_sensor_value："+protation_leftlimit_sensor_value);
        System.out.println("protation_rightlimit_sensor_value："+protation_rightlimit_sensor_value);
        System.out.println("pmin_weight_sensor_value："+pmin_weight_sensor_value);
        System.out.println("pmax_weight_sensor_value："+pmax_weight_sensor_value);
        System.out.println("pfour_rate_max_weight："+pfour_rate_max_weight);
        System.out.println("pfour_rate_max_weight_range："+pfour_rate_max_weight_range);
        System.out.println("pfour_rate_max_range："+pfour_rate_max_range);
        System.out.println("pfour_rate_max_range_weight："+pfour_rate_max_range_weight);
        System.out.println("ptwo_rate_max_weight："+ptwo_rate_max_weight);
        System.out.println("ptwo_rate_max_weight_range："+ptwo_rate_max_weight_range);
        System.out.println("ptwo_rate_max_range："+ptwo_rate_max_range);
        System.out.println("ptwo_rate_max_range_weight："+ptwo_rate_max_range_weight);
        System.out.println("pheight_up_warn_advance："+pheight_up_warn_advance);
        System.out.println("pheight_up_alarm_advance："+pheight_up_alarm_advance);
        System.out.println("pheight_down_warn_advance："+pheight_down_warn_advance);
        System.out.println("pheight_down_alarm_advance："+pheight_down_alarm_advance);
        System.out.println("prange_in_warn_advance："+prange_in_warn_advance);
        System.out.println("prange_in_alarm_advance："+prange_in_alarm_advance);
        System.out.println("prange_out_warn_advance："+prange_out_warn_advance);
        System.out.println("prange_out_alarm_advance："+prange_out_alarm_advance);
        System.out.println("proration_right_warn_advance："+proration_right_warn_advance);
        System.out.println("proration_right_alarm_advance："+proration_right_alarm_advance);
        System.out.println("proration_left_warn_advance："+proration_left_warn_advance);
        System.out.println("proration_left_alarm_advance："+proration_left_alarm_advance);
        System.out.println("pspeed_exchange_weight："+pspeed_exchange_weight);
        System.out.println("pcutting_weight："+pcutting_weight);
        System.out.println("pspeed_exchange_torque："+pspeed_exchange_torque);
        System.out.println("pcutting_torque："+pcutting_torque);
        System.out.println("panti_collision_speedlimit："+panti_collision_speedlimit);
        System.out.println("panti_collision_cutlimit："+panti_collision_cutlimit);
        System.out.println("plocal_No："+plocal_No);
        System.out.println("pchannel_No："+pchannel_No);
        System.out.println("pgroup_No："+pgroup_No);
        System.out.println("plocation_type："+plocation_type);
        System.out.println("plocation_x："+plocation_x);
        System.out.println("plocation_y："+plocation_y);
        System.out.println("plifting_arm_length："+plifting_arm_length);
        System.out.println("pbalance_arm_length："+pbalance_arm_length);
        System.out.println("ptower_body_height："+ptower_body_height);
        System.out.println("ptower_hat_height："+ptower_hat_height);*/

        QueryWrapper<SbTjsb> qw = new QueryWrapper<>();
        qw.eq("sbbh",psn);
        SbTjsb sbTjsb = new SbTjsb();
        sbTjsb.setPrate(prate);
        sbTjsb.setPminHeightSensorValue(pmin_height_sensor_value);
        sbTjsb.setPmaxHeightSensorValue(pmax_height_sensor_value);
        sbTjsb.setPstandardLength(pstandard_length);
        sbTjsb.setPminRange(pmin_range);
        sbTjsb.setPminRangeSensorValue(pmin_range_sensor_value);
        sbTjsb.setPmaxRange(pmax_range);
        sbTjsb.setPmaxRangeSensorValue(pmax_range_sensor_value);
        sbTjsb.setProtationLeftlimitSensorValue(protation_leftlimit_sensor_value);
        sbTjsb.setProtationRightlimitSensorValue(protation_rightlimit_sensor_value);
        sbTjsb.setPminWeightSensorValue(pmin_weight_sensor_value);
        sbTjsb.setPmaxWeightSensorValue(pmax_weight_sensor_value);
        sbTjsb.setPfourRateMaxWeight(pfour_rate_max_weight);
        sbTjsb.setPfourRateMaxWeightRange(pfour_rate_max_weight_range);
        sbTjsb.setPfourRateMaxRange(pfour_rate_max_range);
        sbTjsb.setPfourRateMaxRangeWeight(pfour_rate_max_range_weight);
        sbTjsb.setPtwoRateMaxWeight(ptwo_rate_max_weight);
        sbTjsb.setPtwoRateMaxWeightRange(ptwo_rate_max_weight_range);
        sbTjsb.setPtwoRateMaxRange(ptwo_rate_max_range);
        sbTjsb.setPtwoRateMaxRangeWeight(ptwo_rate_max_range_weight);
        sbTjsb.setPheightUpWarnAdvance(pheight_up_warn_advance);
        sbTjsb.setPheightUpAlarmAdvance(pheight_up_alarm_advance);
        sbTjsb.setPheightDownWarnAdvance(pheight_down_warn_advance);
        sbTjsb.setPheightDownAlarmAdvance(pheight_down_alarm_advance);
        sbTjsb.setPrangeInWarnAdvance(prange_in_warn_advance);
        sbTjsb.setPrangeInAlarmAdvance(prange_in_alarm_advance);
        sbTjsb.setPrangeOutWarnAdvance(prange_out_warn_advance);
        sbTjsb.setPrangeOutAlarmAdvance(prange_out_alarm_advance);
        sbTjsb.setProrationRightWarnAdvance(proration_right_warn_advance);
        sbTjsb.setProrationRightAlarmAdvance(proration_right_alarm_advance);
        sbTjsb.setProrationLeftWarnAdvance(proration_left_warn_advance);
        sbTjsb.setProrationLeftAlarmAdvance(proration_left_alarm_advance);
        sbTjsb.setPspeedExchangeWeight(pspeed_exchange_weight);
        sbTjsb.setPcuttingWeight(pcutting_weight);
        sbTjsb.setPspeedExchangeTorque(pspeed_exchange_torque);
        sbTjsb.setPcuttingTorque(pcutting_torque);
        sbTjsb.setPantiCollisionSpeedlimit(panti_collision_speedlimit);
        sbTjsb.setPantiCollisionCutlimit(panti_collision_cutlimit);
        sbTjsb.setPlocalNo(plocal_No);
        sbTjsb.setPchannelNo(pchannel_No);
        sbTjsb.setPgroupNo(pgroup_No);
        sbTjsb.setPlocationType(plocation_type);
        sbTjsb.setPlocationX(plocation_x);
        sbTjsb.setPlocationY(plocation_y);
        sbTjsb.setPliftingArmLength(plifting_arm_length);
        sbTjsb.setPbalanceArmLength(pbalance_arm_length);
        sbTjsb.setPtowerBodyHeight(ptower_body_height);
        sbTjsb.setPtowerHatHeight(ptower_hat_height);
        sbTjsbService.update(sbTjsb,qw);
        System.out.println("更新参数数据");
    }

    //工作循环（发送每吊次的数据）
    @RequestMapping(value = "/gzxh", method = RequestMethod.POST)
    public void gzxh(String psn,String bdate,String edate,String Duration,String maxHeight,String minHeight,String maxRange,String minRange,String rorationleft,String rorationright,String maxWeight,String maxMoment,String WarnAndAlarm,String CollisionWaranAlarm,String maxMomentpre,String maxMomentrange,String maxMomentweight,String maxMomentSaftweight){
/*        System.out.println("-------------------------------------------------工作循环-------------------------------------------------");
        System.out.println("psn："+psn);
        System.out.println("bdate："+bdate);
        System.out.println("edate："+edate);
        System.out.println("Duration："+Duration);
        System.out.println("maxHeight："+maxHeight);
        System.out.println("minHeight："+minHeight);
        System.out.println("maxRange："+maxRange);
        System.out.println("minRange："+minRange);
        System.out.println("rorationleft："+rorationleft);
        System.out.println("rorationright："+rorationright);
        System.out.println("maxWeight："+maxWeight);
        System.out.println("maxMoment："+maxMoment);
        System.out.println("WarnAndAlarm："+WarnAndAlarm);
        System.out.println("CollisionWaranAlarm："+CollisionWaranAlarm);
        System.out.println("maxMomentpre："+maxMomentpre);
        System.out.println("maxMomentrange："+maxMomentrange);
        System.out.println("maxMomentweight："+maxMomentweight);
        System.out.println("maxMomentSaftweight："+maxMomentSaftweight);*/

        TjGzxh tjGzxh = new TjGzxh();
        tjGzxh.setPen(psn);
        tjGzxh.setBdate(bdate);
        tjGzxh.setEdate(edate);
        tjGzxh.setDuration(Duration);
        tjGzxh.setMaxHeight(maxHeight);
        tjGzxh.setMinHeight(minHeight);
        tjGzxh.setMaxRange(maxRange);
        tjGzxh.setMinRange(minRange);
        tjGzxh.setRorationleft(rorationleft);
        tjGzxh.setRorationright(rorationright);
        tjGzxh.setMaxWeight(maxWeight);
        tjGzxh.setMaxMoment(maxMoment);
        tjGzxh.setWarnAndAlarm(WarnAndAlarm);
        tjGzxh.setCollisionWaranAlarm(CollisionWaranAlarm);
        tjGzxh.setMaxMomentpre(maxMomentpre);
        tjGzxh.setMaxMomentrange(maxMomentrange);
        tjGzxh.setMaxMomentweight(maxMomentweight);
        tjGzxh.setMaxMomentSaftweight(maxMomentSaftweight);
        tjGzxhService.save(tjGzxh);
        System.out.println("工作循环数据");
    }

    //考勤记录
    @RequestMapping(value = "/kqjl", method = RequestMethod.POST)
    public void kqjl(String sn,String time,String driverid,String eType){
/*        System.out.println("-------------------------------------------------考勤记录-------------------------------------------------");
        System.out.println("sn："+sn);
        System.out.println("time："+time);
        System.out.println("driverid："+driverid);
        System.out.println("eType："+eType);*/
        TjSjXx t = new TjSjXx();
        t.setSn(sn);
        t.setTime(time);
        t.setDriverid(driverid);
        t.setE_type(eType);
        tjSjService.save(t);
        System.out.println("添加考勤记录");
    }
}
